import pytest

from common.NeqReq import NeqReq
from common.DBManager import DBManager

from utils.yaml_utils import read_yaml
from utils.url_utils import full_url
from utils.data_process_utils import extract_args
from utils.cycle_utils import *


url = "/user/deleteBankCard/"
login_url = '/login/verifyLogin'

data_path = "./data/delete_bank_card.yaml"
pre_path = "./data/setup/delete_bank_card.yaml"

class Test_deleteBankCard:
    
	@pytest.fixture(scope="function",  autouse=True)
	def function_cycle(self):

		dm = DBManager()   
		pre_process(dm, pre_path)
		yield
		dm.close()


	@pytest.mark.parametrize("args", read_yaml(data_path))
	def test_1(self,args):
        
		nr = NeqReq()

		if not args.get('no_auth'):
			print("登录")
			nr.send_request('GET', full_url(login_url), {
				"username": 'zhangsan',
				"password": 'e10adc3949ba59abbe56e057f20f883e'
			})

		result = nr.send_request('DELETE', full_url(url, [args.get('bankcardid')]))

		assert result['code'] == args['exp1']
		if result['code'] == 200:
			body = result['body']
			assert body.get('code') == args['exp2']

